﻿using Chat_IService;
using Chat_Model;
using Chat_Model.ViewModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace Chat_Service
{
    public class LarUsersFriendsApplyService : BaseService<LarUsersFriendsApply>, ILarUsersFriendsApplyService
    {
        /// <summary>
        /// 好友申请列表
        /// </summary>
        public async Task<List<LarUsersFriendsApplyDto>> GetContactsApplyList(
            int uid , int page, int pageSize)
        {
            var list = await Context.Queryable<LarUsersFriendsApply>()
               .LeftJoin<LarUsersFriends>((a, f) => a.UserId == f.FriendId && uid == f.UserId)
               .LeftJoin<LarUsers>((a, f, u) => a.UserId == u.Id)
               .Where(a => a.FriendId == uid)
               .Select((a, f, u) => new LarUsersFriendsApplyDto
               {
                   Id=a.Id,
                   User_Id = a.UserId,
                   Avatar = u.Avatar,
                   NickName = u.Nickname,
                   Status = f.Status,
                   Created_At = (DateTime)a.CreatedAt,
                   Remarks = a.Remark
               })
               .ToPageListAsync(page, pageSize);
            return list;
        }
    }
}